package com.Demo;

//单选框和复选框
import javax.swing.*;
import java.awt.*;
import java.net.URL;

//按钮
public class JButtonDemo01 extends JFrame {
    public JButtonDemo01() throws HeadlessException {
        Container container = this.getContentPane();
        //将一个图片变为图标
        URL resource = JButtonDemo.class.getResource("carrot.jpg");
        Icon icon = new ImageIcon(resource);

//        //单选框
//        JRadioButton radioButton1 = new JRadioButton("JRadioButton01");
//        JRadioButton radioButton2 = new JRadioButton("JRadioButton02");
//        JRadioButton radioButton3 = new JRadioButton("JRadioButton03");
//        //由于单选框只能选择一个，分组，一个组中只能选择一个
//        ButtonGroup group = new ButtonGroup();
//        group.add(radioButton1);
//        group.add(radioButton2);
//        group.add(radioButton3);
//
//        container.add(radioButton1,BorderLayout.CENTER);
//        container.add(radioButton2,BorderLayout.NORTH);
//        container.add(radioButton3,BorderLayout.SOUTH);


        //复选框
        JCheckBox checkBox01 = new JCheckBox("checkBox01");
        JCheckBox checkBox02 = new JCheckBox("checkBox02");
        JCheckBox checkBox03 = new JCheckBox("checkBox03");

        container.add(checkBox01,BorderLayout.CENTER);
        container.add(checkBox02,BorderLayout.NORTH);
        container.add(checkBox03,BorderLayout.SOUTH);

        //add
        //container.add(button);

        this.setVisible(true);
        this.setBounds(400,400,300,400);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }

    public static void main(String[] args) {
        new JButtonDemo01();
    }
}
